// axios封装
import axios from 'axios';

// 使用sessionStorage
let token = window.sessionStorage.getItem('token');
const service = axios.create({
  // baseurl
  baseURL: 'http://localhost:8080/',

  // 超时
  timeout: 20000
});
service.interceptors.request.use(
  config => {
    // Do something before request is sent
    // 添加请求头
    config.headers.token = token;
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
service.interceptors.response.use(
  response => {
    // Do something before response is sent

    return response;
  },
  error => {
    // Do something with response error
    return Promise.reject(error);
  }
);
// 暴露出axios
export default service;
